// mysql_config.js
const Sequelize = require('sequelize');

// const sequelize = new Sequelize({
//     database: 'qingdu_app',
//     username: 'root',
//     password: 'mac1',
//     host: '127.0.0.1',
//     dialect: 'mysql',
//     pool: {
//         max: 5,
//         min: 0,
//         acquire: 5000,   // 建议给大一点，500ms 经常不够
//         idle: 10000
//     },
//     logging: console.log
// });

const sequelize = new Sequelize({
    database: 'qingdu_app',
    username: 'qingdu_app',
    password: 'dawan0528',
    host: '101.37.75.144',
    dialect: 'mysql',
    pool: {
        max: 5,
        min: 0,
        acquire: 5000,   // 建议给大一点，500ms 经常不够
        idle: 10000
    },
    logging: console.log
});
async function testConn() {
    try {
        await sequelize.authenticate();   // 真正等待
        console.log('连接建立成功');
    } catch (e) {
        console.log('连接建立失败');
        throw new Error(`无法连接数据库: ${e.message}`);
    }
}

module.exports = { testConn, sequelize };
